home *** CD-ROM | disk | FTP | other *** search
/ Mission to McDonaldLand / Mission To McDonaldLand.iso / calnz.dxr / 00009_Script_AnimatedCast < prev    next >
Text File  |  1998-10-25  |  7KB  |  222 lines

  1. property myChannel,myCastList,myink,myForecolor,myBackcolor,currentFrame,mytype¼
  2. myRegPoint,MyLoc,NumberOfFrames,animationTempo,AnimstartTime,title,Objs,type,numLoops,loopCounter,¼
  3. stopCriteria,manualChannel,startSound,endSound,PLayedEndSound,Callback,WasIrunning
  4. --myChannel = sprite channel
  5. --myCastlist = list of castnumbers that make up frames of animation
  6. --myInk = ink to display sprite
  7. --forecolor,backcolor obvious
  8. --currentframe = currentframe being displayed
  9. --myRegPoint ,Myloc- obvious
  10. --Number of frames = the number of frames in the animation sequence
  11. --Animation tempo = the delay to put inbetween frames
  12. --AnimStarttime = time current frame was put onto screen, using ticks
  13. --title = title for this object, used by object handlers
  14. --Objs = the Object Handlers Object
  15. --type = #animatedCast, used by ObjectHandlers routines for searching
  16. --numLoops = the total number of frames to display, eg if 6 frames in the anim if you put 12
  17. --                        in as numloops it would play anim twice
  18. --loopcounter = tmp variable used for seeing what iteration of the loop we're in
  19. --stopCriteria = the number of loops to display, if -1 only 1st frame displayed
  20. --ManualChannel = true if a channel was manually passed as a param
  21. --Startsound = sound to play when opbject loaded
  22. --endSound = sound to play when object reaches stop criteria
  23. --playedEndSound = true if have already played end sound
  24.  
  25. on birth me,titleP,ObjsP,tempo,NumLoopsP,CastListIn,LocIn,inkIn,forecolorIn,¼
  26. BackcolorIn,thisChannel,StartSoundP,EndSoundP,CallBackP
  27.   
  28.   --start anim at 1st cast ember in list
  29.   set currentFrame = 1
  30.   set numLoops = numLoopsP
  31.   set stopCriteria = numLoops
  32.   set loopcounter = 1
  33.   set mytype = #animatedCast
  34.   set Objs = ObjsP
  35.   set myCastList = CastListIn
  36.   --preload all members used in anim
  37.   repeat  with loadme in myCastList
  38.     preLoadMember member loadme
  39.   end repeat
  40.   
  41.   set myInk = InkIn
  42.   set myForecolor = ForeColorIn
  43.   set myBackColor = BackcolorIn
  44.   set title = titleP
  45.   
  46.   --was a manual channel allocated
  47.   if voidP(thisChannel) then
  48.     put getfreeChan(the freechan of Objs) into MyChannel
  49.     set manualChannel = FALSE
  50.   else
  51.     set myChannel = thisChannel
  52.     set manualChannel = true
  53.   end if
  54.   set myLoc = LocIn
  55.   
  56.   --assign the delay
  57.   set animationTempo = tempo
  58.   --store time for first frame anim
  59.   set animStartTime = the ticks
  60.   assignPicCast(mychannel,getat(MyCastList,1),myink,myLoc,myBackColor)
  61.   --should we play a sound for starting the anim
  62.   if VoidP(startsoundP) = FALSE then
  63.     set StartSound = StartSoundP
  64.     puppetsound 1,0
  65.     puppetsound 1,startsound
  66.   end if
  67.   --should we play a sound when the anim finishes?
  68.   if VoidP(endSoundP)=FALSE then
  69.     set endSound = endSoundP
  70.     set  PLayedEndSound= false
  71.   end if
  72.   --assign how many frames in this anim
  73.   set NumberOfFrames = count(MyCastlist)
  74.   --callback functionality for when movie stops running
  75.   if voidP(callbackP) = false then
  76.     set Callback = callbackP
  77.   end if
  78.   --stops stepframe from executing the callback function
  79.   if  NumLoops < 0 then
  80.     set wasIRunning = false
  81.   else
  82.     set wasIrunning = true
  83.   end if
  84.   
  85.   append(the actorlist,me)
  86.   return me
  87. end birth
  88.  
  89. --show next frame of the anim, if reached end reset to first in castlist for next time
  90. --round
  91. on showNextFrame me
  92.   if currentFrame < NumberofFrames then
  93.     set currentFrame = currentFrame + 1
  94.   else
  95.     set currentFrame = 1
  96.   end if
  97.   set the member of sprite myChannel = getat(myCastList,CurrentFrame)
  98. end showNextFrame
  99.  
  100. on NewCastlist me,CastListP,NumFrames
  101.   set myCastlist =[]
  102.   repeat with i in CastListP
  103.     append(myCastList,i)
  104.     preload member i
  105.   end repeat
  106.   set currentframe = 1
  107.   set NumberOfFrames = count(MyCastlist)
  108.   set stopCriteria = numframes
  109. end
  110.  
  111. on stepFrame me
  112.   
  113.   --have we reached the desired delay between frames?
  114.   if the ticks < animStartTime + animationTempo then
  115.     --no we havent
  116.     nothing
  117.     --following true if  we are in loop infinatley mode  
  118.   else  if stopCriteria < 0 then
  119.     showNextFrame(me)
  120.     set animStartTime = the ticks
  121.     --following FALSE if we've reached the final number of TOTAl frames, including looping round 
  122.   else  if loopCounter<= StopCriteria then
  123.     set loopCounter = loopCounter + 1
  124.     showNextFrame(me)
  125.     set animStartTime = the ticks
  126.   else 
  127.     --in here is stuff for when the animation is finished
  128.     --here we play a sound on anim finish
  129.     if (playedEndsound = False) and VoidP(endSound)=FALSE then
  130.       puppetsound 2,0
  131.       puppetsound 2,endsound
  132.       set playedEndSound = true
  133.     end if
  134.     --if there is a callback execute it
  135.     if voidP(callback)=FALSE  and wasIrunning = TRUE then
  136.       set wasIRunning = FALSE
  137.       do callback
  138.     end if
  139.   end if
  140.   
  141. end stepframe
  142.  
  143. --make the anim loop between frame startframe and endframe
  144. --reassigns the list of castmembers that make up the loop
  145. on LoopBetween me,startFrame,Endframe
  146.   set tmpCastLoop = []
  147.   repeat with i = startframe to endframe
  148.     append(tmpCastLoop,getat(myCastList,i))
  149.   end repeat
  150.   set myCastlist =[]
  151.   repeat with i in tmpCastLoop
  152.     append(myCastList,i)
  153.   end repeat
  154.   set currentframe = 1
  155.   set NumberOfFrames = count(MyCastlist)
  156.   set stopCriteria = -1
  157. end
  158.  
  159. on moveObjectOffScreen me
  160.   set the loc of sprite myChannel = point(-1000,-1000)
  161. end moveObjectOffScreen
  162.  
  163. On MoveObject me,NewLoc
  164.   set myLoc =newloc
  165.   set the loc of sprite myChannel =newLoc
  166. end
  167.  
  168.  
  169. on kill me
  170.   set the loc of sprite mychannel to  point(-2000,-2000)
  171.   if VoidP(startsound) = FALSE then
  172.     puppetsound 1,0
  173.   end if
  174.   if VoidP(endSound)=FALSE then
  175.     puppetsound 2,0
  176.   end if
  177.   if ManualChannel =FALSE then
  178.     releasechan(the FreeChan of Objs,MyChannel )
  179.   end if
  180.   puppetsprite myChannel,False
  181.   delfromactorlist(objs,me)
  182. end kill
  183.  
  184. on switchOffObj me
  185.   set the loc of sprite mychannel to  point(-2000,-2000)
  186.   if VoidP(startsound) = FALSE then
  187.     puppetsound 1,0
  188.   end if
  189.   if VoidP(endSound)=FALSE then
  190.     puppetsound 2,0
  191.   end if
  192.   if ManualChannel =FALSE then
  193.     releasechan(the FreeChan of Objs,MyChannel )
  194.   end if
  195.   set currentframe = 1
  196.   puppetsprite myChannel,False
  197.   delfromactorlist(objs,me)
  198. end
  199.  
  200. on switchOnObj me
  201.   if manualChannel = FALSE then
  202.     set MyChannel to getfreeChan(the FreeChan of objs) 
  203.   end if
  204.   assignPicCast(mychannel,getat(MyCastList,currentframe),myink,myLoc,myBackColor)
  205.   append(the actorlist,me)
  206.   if VoidP(startsound) = FALSE then
  207.     puppetsound 1,startsound
  208.   end if
  209. end
  210.  
  211. on redrawObject me
  212.   assignPicCast(mychannel,getat(MyCastList,currentframe),myink,myLoc,myBackColor)
  213. end
  214.  
  215. on enable me
  216.   append(the actorlist,me)
  217. end
  218.  
  219. on disable me
  220.   delfromactorlist(objs,me)
  221. end
  222.